package DataAnalysis_qcl

import org.apache.spark.sql.SparkSession

import java.util.Properties

object DataAnalysis06 {
  def main(args: Array[String]): Unit = {
    /*
          DataAnalysis06:分析租房信息里面价格最贵的租房，房源的详细信息
     */
    val spark=SparkSession.builder()
      .master("local[*]")
      .appName("DataAnalysis06")
      .enableHiveSupport()
      .getOrCreate()

      val mysql_connect=new Properties()
      mysql_connect.setProperty("user","root")
      mysql_connect.setProperty("password","123456")
      mysql_connect.setProperty("driver","com.mysql.jdbc.Driver")

    spark.read.jdbc("jdbc:mysql://192.168.40.110:3306/qcl?useSSL=false","data_processing",mysql_connect)
      .createOrReplaceTempView("data")

    spark.sql("use qcl")

   val result= spark.sql(
      """
        |select
        |money,
        |plot,
        |area,
        |downtown,
        |house_type,
        |landlord
        |from data
        |order by money desc
        |limit 10
        |""".stripMargin)

    result.write.mode("overwrite")
      .jdbc("jdbc:mysql://192.168.40.110:3306/qcl?useSSL=false", "data_analysis06", mysql_connect)

    //  将结果存入hdfs
    result.repartition(1).write.mode("overwrite")
      .csv("/qcl/data_analysis/data_analysis06.csv")


    spark.close()
  }

}
